package com.sy.core.web;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.sy.core.model.SysUser;
import com.sy.core.model.common.Permissions;
import com.sy.core.service.SysMenuService;
import com.sy.core.service.SysRelationService;
import com.sy.core.service.SysRoleService;
import com.sy.core.service.SysUserService;

public class BaseCtl {
    protected final Logger logger = LoggerFactory.getLogger(BaseCtl.class);
    @Autowired
    protected  SysUserService sysUserService;
    @Autowired
    protected SysMenuService sysMenuService;
    @Autowired
    protected SysRoleService sysRoleService;
    @Autowired
    protected SysRelationService sysRelationService;
//    @Resource
//    protected RedisTemplate<Object,Object> template;
    /*@Autowired
    protected HttpServletResponse response;*/
    
    public SysUser getLoginUser() {
    	Subject subject = SecurityUtils.getSubject();
    	 Object obj = subject.getPrincipal();
         Permissions permissions = new Permissions();
         if(obj instanceof Permissions) {
             permissions = (Permissions) obj;
         } else {
             permissions = JSON.parseObject(JSON.toJSON(obj).toString(), Permissions.class);
         }
         return permissions.getSysUser();
    }
    
    public String getCurrentTime() {
    	return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }
}
